// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Diagnostics.CodeAnalysis;
using NSQL.Expressions;

namespace NSQL.Extensions
{
    [SuppressMessage("ReSharper", "UnusedMember.Global")]
    public static class PredicateExpressionExtensions
    {
        public static IPredicateExpression And(this IPredicateExpression self, IPredicateExpression other)
        {
            if (self is null || EmptyExpression.Instance.Equals(self)) return other;
            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (other is null || EmptyExpression.Instance.Equals(other)) return self;
            return new LogicalExpression(self, other, LogicalOperator.And);
        }
        public static IPredicateExpression Or(this IPredicateExpression self, IPredicateExpression other)
        {
            if (self is null || EmptyExpression.Instance.Equals(self)) return other;
            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (other is null || EmptyExpression.Instance.Equals(other)) return self;
            return new LogicalExpression(self, other, LogicalOperator.Or);
        }
        public static INotExpression Not(this IPredicateExpression self)
        {
            return self is null || EmptyExpression.Instance.Equals(self) ? null : new NotExpression(self);
        }
    }
}